import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from '../../shared/shared.module';
import { app, os, updater } from '@neutralinojs/lib';

@Component({
  selector: 'app-welcome',
  standalone: true,
  templateUrl: './welcome.component.html',
  styleUrl: './welcome.component.scss',
  imports: [CommonModule, SharedModule],
})
export class WelcomeComponent {
  checkUpdate() {
    app.getConfig().then(config => {
      let currentApplicationId = config.version;
      let url = 'https://docs.codeforfun.cn/static/update_manifest.json';
      updater.checkForUpdates(url).then(manifest => {
        console.log('checkForUpdates r', manifest);
        if (manifest.version !== currentApplicationId) {
          console.log('该升级啦');
          let command = `curl ${manifest.resourcesURL} --output resources.neu`;
          os.execCommand(command).then(() => {
            app.restartProcess().then();
          });
        }
      });
    });
  }

  test() {
    // app.getConfig().then(r => {
    //   console.log('getConfig r', r);
    //   clipboard.writeText(JSON.stringify(r)).then(() => {
    //     console.log('复制成功');
    //   });
    // });


  }

}
